﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CourseUtils;
using DreamHome.Models;
using DreamHome.Repositories;

namespace DreamHome.Services
{
    class BranchService
    {
        private BranchRepository _branchRepository;
        private StaffRepository _staffRepository;

        public BranchService(BranchRepository repository)
        {
            if (repository == null)
                throw new ArgumentNullException("repository");

            _branchRepository = repository;
        }

        public void CreateBranch()
        {
            String branchNo = CourseUtils.IOHelpers.ReadStringFromConsole("insert branchNo [1 letter and 3 simbols]\n");
            String street = CourseUtils.IOHelpers.ReadStringFromConsole("insert a street address");
            String city = CourseUtils.IOHelpers.ReadStringFromConsole("insert city of branch");
            String postcode = CourseUtils.IOHelpers.ReadStringFromConsole("insert postcode");
            bool isValid = true;

            Branch branch = new Branch(branchNo, street, city, postcode, isValid);

            _branchRepository.CreateBranch(branch);
        }


        #region get all branches from Branch table using select method

        public void SelectAllFromBranchTable()
        {
            List<Branch> allFromBranchTable = new List<Branch>();
            allFromBranchTable = _branchRepository.SelectAllFromBranch(allFromBranchTable);
            Console.WriteLine("\nSELECT * FROM branch \nBranchNo ; street ; city ; postcode ; IsValid\n");
            foreach (Branch record in allFromBranchTable)
                Console.WriteLine("{0} ; {1} ; {2} ; {3} ; {4}", record.branchNo, record.street, record.city, record.postcode, record.IsValid);
            Console.WriteLine("\nPress any key to continue");
            Console.ReadKey();
        }
        #endregion

    }
}